var mgeMxgl = {
    tableid: "table1",
    layerindex: null,
    bsTable: null,
    idselect: null
};


mgeMxgl.initColumn = function () {
    return [[/*{
     field: 'selectItem', radio: true
     },*/
        {
            title: '模型ID号', field: 'mxId', width: '100px', halign: 'center', align: 'left', valign: 'middle'
        }, {
            title: '模型分类', field: 'mxfl', width: "100px", halign: 'center', align: 'left', valign: 'middle'
        }, {
            title: '模型所属行业/税种', field: 'sz', width: "150px", halign: 'center', align: 'left', valign: 'middle', formatter: function (v) {
                return v;
            }
        }, {
            title: '风险名称', field: 'fxmc', width: "200px", halign: 'center', align: 'left', valign: 'middle', formatter: function (v) {
                return v;
            }
        }, {
            title: '风险等级', field: 'fxdj', width: "150px", halign: 'center', align: 'left', valign: 'middle', formatter: function (v, row) {
                return v;
            }
        }, {
            title: '描述', field: 'ms', width: "170px", halign: 'center', align: 'left', valign: 'middle', formatter: function (v, r, i) {
                return v;
            }
        }, {
            title: '涉及数据说明', field: 'sjsjsm', width: "120px", halign: 'center', align: 'left', valign: 'middle', formatter: function (v, r, i) {
                return v;
            }
        }

    ]];
}
mgeMxgl.queryParams = function () {
    var c = cmm.serializeObject($("#form_search"));
    return c;
}
mgeMxgl.resHeigth = function () {
    var he = $(window).height() - ($("#divsearch").height() + 20);
    return he;
}
/*mgeMxgl.select = function () {
 var s = $("sz").chosen({width: '100%', disable_search: true});
 //show.bs.select
 //shown.bs.select 当下拉菜单对用户可见出发
 //loaded.bs.select 初始化后触发
 //hide.bs.select
 $("sz").on("change", function (e, params) {

 });
 return s;
 }*/

var myLayout;
$(function () {
    componentsGo();
    myLayout = $('body').layout({
        north__minSize: 50, north__maxSize: 400, togglerContent_open: '<div class="ui-icon"></div>', togglerContent_closed: '<div class="ui-icon"></div>'
        // , spacing_open: 10
        // , spacing_closed: 10
    });
    var bs = new BgdataTable();
    var opt = new BgOption(mgeMxgl.tableid, ctx + "/mge/adx/syfx/zhfx/queryFxfxMxgl?rad=" + new Date().getTime(), mgeMxgl.initColumn(), mgeMxgl.queryParams(), mgeMxgl.resHeigth());
    /* opt.toolbarId = "table1Toolbar";
     opt.onClickRow = function (row, el, field) {
     if (row.userId == "1") {
     $("#update").hide();
     $("#del").hide();
     } else {
     $("#update").show();
     $("#del").show();
     }
     }*/
    bs.draw(opt);
    mgeMxgl.bsTable = bs;
    $("#form_search").on("submit", function (e) {
        bs.refresh(mgeMxgl.queryParams());
        return false;
    });
    /* mgeUser.addOnClick();
     mgeUser.updateOnClick();
     mgeUser.delOnClick();*/
    //mgeMxgl.idselect = mgeMxgl.select();
    //mgeMxgl.postAjaxFrom();
});


function getSzZsxm() {

    var lay1 = layer.load({shade: [0.1]});
    $.ajax({
        url: ctx + "/mge/adx/syfx/zhfx/querySzZsxm",
        data: {},
        dataType: "json",
        type: 'post',
        success: function (d, s) {

            layer.close(lay1);
            if (d.code == '200') {
                var datas = d.data;
                $('#sd2').empty();
                $('#sd2').append("<option value=''>" + "全部" + "</option>");
                for (var i = 0; i < datas.length; i++) {
                    $('#sd2').append("<option value='" + datas[i].zsxmDm + "'>" + datas[i].zsxmmc + "</option>");
                }
                $("#sd2").trigger("chosen:updated");

            } else {
                layer.alert(d.message);
            }
        }, error: function (sta) {
            layer.close(lay1);
            layer.alert("请求失败，请重试或检查网络！");
        }
    });
}

function componentsGo() {
    $('.bs-select').chosen({
        width: '170px',
        disable_search: true
    });
    $("#sd6").chosen({disable_search: true});
    $("#s_starttime").chosen({disable_search: true,});
    $("#sd2").chosen({disable_search: true});
    getSzZsxm();
    //初始化禁用
    $('#s_starttime').prop('disabled', true);
    $("#s_starttime").trigger("chosen:updated");
    $('#sd2').prop('disabled', true);
    $("#s_starttime").trigger("chosen:updated");

    //监听事件
    $("#sd6").on('change', function () {
        var mxfl = $("#sd6").val();

        if ((mxfl == '单税种风险模型')) {
            $('#sd2').prop('disabled', false);
            $("#sd2").trigger("chosen:updated");
            $('#s_starttime').prop('disabled', true);
            $("#s_starttime").trigger("chosen:updated");

        } else if (mxfl == '行业风险模型') {
            $('#sd2').prop('disabled', true);
            $("#sd2").trigger("chosen:updated");
            $('#s_starttime').prop('disabled', false);
            $("#s_starttime").trigger("chosen:updated");
        } else {
            $('#sd2').prop('disabled', true);
            $("#sd2").trigger("chosen:updated");
            $('#s_starttime').prop('disabled', true);
            $("#s_starttime").trigger("chosen:updated");
        }
    })
}
